package com.ruoyi.bearing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.bearing.domain.ModelTrain;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bearing.domain.ModelInfoMangment;
import com.ruoyi.bearing.service.IModelInfoMangmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模型管理Controller
 */

@Api("模型信息管理")
@RestController
@RequestMapping("/model/mangment")
public class ModelInfoMangmentController extends BaseController {
    @Autowired
    private IModelInfoMangmentService modelInfoMangmentService;

    /**
     * 查询模型列表
     */
    @ApiOperation("查询模型列表")
    @PreAuthorize("@ss.hasPermi('model:mangment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ModelInfoMangment modelInfoMangment) {
        startPage();
        List<ModelInfoMangment> list = modelInfoMangmentService.selectModelInfoMangmentList(modelInfoMangment);
        return getDataTable(list);
    }

    /**
     * 导出模型列表
     */
    @ApiOperation("导出模型列表")
    @PreAuthorize("@ss.hasPermi('model:mangment:export')")
    @Log(title = "模型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ModelInfoMangment modelInfoMangment) {
        List<ModelInfoMangment> list = modelInfoMangmentService.selectModelInfoMangmentList(modelInfoMangment);
        ExcelUtil<ModelInfoMangment> util = new ExcelUtil<ModelInfoMangment>(ModelInfoMangment.class);
        util.exportExcel(response, list, "模型管理数据");
    }

    /**
     * 下载
     */
    @ApiOperation("下载模型参数")
    @PreAuthorize("@ss.hasPermi('model:mangment:download')")
    @Log(title = "模型管理", businessType = BusinessType.DOWNLOAD)
    @PostMapping("/download")
    public void download(HttpServletResponse response, ModelInfoMangment modelInfoMangment) {
        List<ModelTrain> list = modelInfoMangmentService.getModelInfoByMid(modelInfoMangment);
        ExcelUtil<ModelTrain> util = new ExcelUtil<ModelTrain>(ModelTrain.class);
        util.exportExcel(response, list, "模型参数");
    }

    /**
     * 获取模型管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:mangment:query')")
    @GetMapping(value = "/{mid}")
    public AjaxResult getInfo(@PathVariable("mid") String mid) {
        return success(modelInfoMangmentService.selectModelInfoMangmentByMid(mid));
    }

    /**
     * 新增模型管理
     */
    @PreAuthorize("@ss.hasPermi('model:mangment:add')")
    @Log(title = "模型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ModelInfoMangment modelInfoMangment) {
        return toAjax(modelInfoMangmentService.insertModelInfoMangment(modelInfoMangment));
    }

    /**
     * 修改模型管理
     */
    @PreAuthorize("@ss.hasPermi('model:mangment:edit')")
    @Log(title = "模型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ModelInfoMangment modelInfoMangment) {
        return toAjax(modelInfoMangmentService.updateModelInfoMangment(modelInfoMangment));
    }

    /**
     * 删除模型训练信息
     */
    @ApiOperation("删除模型训练信息")
    @PreAuthorize("@ss.hasPermi('model:mangment:remove')")
    @Log(title = "模型管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{mids}")
    public AjaxResult remove(@PathVariable String[] mids) {
        return toAjax(modelInfoMangmentService.deleteModelInfoMangmentByMids(mids));
    }
}
